extends Control
@onready var h_box_container = $HBoxContainer/HBoxContainer4

const texture_array = [preload("res://textures/Numbers/number0.png"), preload("res://textures/Numbers/number1.png"), preload("res://textures/Numbers/number2.png"), preload("res://textures/Numbers/number3.png"), preload("res://textures/Numbers/number4.png"), preload("res://textures/Numbers/number5.png"), preload("res://textures/Numbers/number6.png"), preload("res://textures/Numbers/number7.png"), preload("res://textures/Numbers/number8.png"), preload("res://textures/Numbers/number9.png")]
@onready var texture_stars_array = [$HBoxContainer/HBoxContainer/HBoxContainer, $HBoxContainer/HBoxContainer2/HBoxContainer2, $HBoxContainer/HBoxContainer3/HBoxContainer3]
var score_str:String = ""

# 更新分数或者星星数量
func update_result(num:int,h_box:HBoxContainer):
	var array = str(num)
	for i in range(array.length()):
		if(h_box.get_child_count()<=i):
			var texture_rect = TextureRect.new()
			texture_rect.set_texture(texture_array[int(array[i])])
			h_box.add_child(texture_rect)
		else:
			h_box.get_child(i).set_texture(texture_array[int(array[i])])


# 显示分数
func update_score(score:int):
	# 分数为0说明清空重来了
	if score == 0:
		for child in h_box_container.get_children():
			child.queue_free()
	update_result(score,h_box_container)
	
# 获取到星星时记录星星数量
func update_stars_count(stars_array):
	for i in range(stars_array.size()):
		update_result(stars_array[i],texture_stars_array[i])
